FROM maven:3.8-openjdk-11 AS build
WORKDIR /app

# Copy the POM file first for dependency resolution
COPY pom.xml .
# Download dependencies to cache them in a layer
RUN mvn dependency:go-offline -B

# Copy the source code
COPY src ./src

# Build the application
RUN mvn package -DskipTests

# Runtime stage
FROM openjdk:11-jre-slim
WORKDIR /app

# Copy the JAR file from the build stage
COPY --from=build /app/target/*.jar app.jar

# OpenTelemetry Java agent for distributed tracing
RUN apt-get update && apt-get install -y curl && \
    curl -L https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.7.0/opentelemetry-javaagent-all.jar -o opentelemetry-javaagent.jar && \
    apt-get remove -y curl && apt-get clean && rm -rf /var/lib/apt/lists/*

# Run with OpenTelemetry Java agent
ENTRYPOINT ["java", "-javaagent:opentelemetry-javaagent.jar", "-jar", "app.jar"] 